cmake_minimum_required(VERSION 3.15)
project(PyUTSC)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_BUILD_TYPE Release)

if (MSVC)
    add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")
endif ()

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/out/build/OpenUTSC/PyUTSC)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/out/build/OpenUTSC/PyUTSC)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/out/build/OpenUTSC/PyUTSC)

include_directories("${CMAKE_SOURCE_DIR}/3rdlibs/include")
link_directories("${CMAKE_SOURCE_DIR}/3rdlibs/lib")


#寻找PYTHONHOME的环境变量
find_package (Python3 COMPONENTS Interpreter Development)
include_directories(${Python3_INCLUDE_DIRS})
link_libraries(${Python3_LIBRARIES})

message(STATUS "Found Python version: ${Python3_VERSION}")

# 指定 SWIG 路径
set(SWIG_EXECUTABLE "${CMAKE_SOURCE_DIR}/3rdlibs/bin/swig/swig.exe")
set(SWIG_DIR "${CMAKE_SOURCE_DIR}/3rdlibs/lib/swig/Lib")
find_package(SWIG REQUIRED)
include(${SWIG_USE_FILE})
message("SWIG_USE_FILE:${SWIG_USE_FILE}")
message("SWIG_DIR::${SWIG_DIR}")

#Python文件输出目录 -outdir
set(CMAKE_SWIG_OUTDIR ${CMAKE_SOURCE_DIR}/out/build/OpenUTSC/PyUTSC)
#指定一个输出目录名，用于放置生成的源文件。
set(SWIG_OUTFILE_DIR ${CMAKE_SOURCE_DIR}/PyUTSC)

#c ++模式
set_property(SOURCE PyUTSC.i PROPERTY CPLUSPLUS ON)

# SWIG接口文件
set(SWIG_INTERFACE_FILE PyUTSC.i)

# 开始生成
swig_add_library(PyUTSC LANGUAGE python
        SOURCES PyUTSC.i
        "../LibUTSCKernel/LibUTSCKernel.cpp"
        "../LibUTSCKernel/UTSCImpl.cpp"

)

# PYD
target_compile_definitions(PyUTSC PRIVATE BUILDING_PYD)

swig_link_libraries(PyUTSC ${PYTHON_LIBRARIES})


